﻿using System;
using System.Collections;
using System.Data;
using System.Text;

namespace Coffee.Lists
{
    public class cls_UnitRate
    {
        TSoft.Data.DataLayer DBLayer;
        public cls_UnitRate()
        {
            DBLayer = new TSoft.Data.DataLayer();
        }

        public DataTable GetAll()
        {
            return DBLayer.ExecDataTable("sp_Lst_RateUnit", "Command", "GetAll");
        }

        public void Update(ref System.Data.DataTable Data)
        {
            try
            {
                Hashtable output = null;
                DBLayer.BeginTransaction();

                foreach (DataRow row in Data.Rows)
                {
                    if (row.RowState == DataRowState.Added || row.RowState == DataRowState.Modified)
                    {
                        DBLayer.ExecNonQuery("sp_Lst_RateUnit", "Command,FUID,TUID,Rate", ref output, "Update",
                            TSoft.Cvert.ToInt32(row["FUID"], 0), TSoft.Cvert.ToInt32(row["TUID"], 0),
                            TSoft.Cvert.ToDecimal(row["Rate"], 0));
                    }
                }

                DBLayer.CommitTransaction();
            }
            catch
            {
                DBLayer.RollbackTransaction();
            }
        }

        public void DeleteRow(DataRow Row)
        {
            DBLayer.ExecNonQuery("sp_Lst_RateUnit", "Command,FUID,TUID", "DeleteRow", TSoft.Cvert.ToInt32(Row["FUID"], 0), TSoft.Cvert.ToInt32(Row["TUID"], 0));
        }
    }
}
